package top.mccat.raven.combatstatus;

import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import top.mccat.raven.combatstatus.domain.CombatConfig;
import top.mccat.raven.combatstatus.factory.ConfigFactory;
import top.mccat.raven.combatstatus.handler.CommandHandler;
import top.mccat.raven.combatstatus.listener.FightEventListener;
import top.mccat.raven.combatstatus.utils.MsgUtils;

/**
 * @author Distance
 */
public class CombatStatus extends JavaPlugin {
    private ConfigFactory configFactory;
    private CombatConfig combatConfig;
    private MsgUtils msgUtils;
    private CommandHandler commandHandler;
    private FightEventListener eventListener;
    @Override
    public void onLoad() {
        // Plugin load config
        configFactory = new ConfigFactory(this, msgUtils);
        configFactory.authorMenu();
        combatConfig = configFactory.readCombatConfig();
        msgUtils = new MsgUtils(combatConfig);
    }

    @Override
    public void onEnable() {
        // Plugin startup logic
        commandHandler = new CommandHandler(this,msgUtils);
        eventListener = new FightEventListener(this,msgUtils,combatConfig);
        Bukkit.getPluginCommand("cs").setExecutor(commandHandler);
        getServer().getPluginManager().registerEvents(eventListener,this);
    }

    @Override
    public void reloadConfig() {
        combatConfig = configFactory.readCombatConfig();
        msgUtils.setCombatConfig(combatConfig);
        eventListener.setCombatConfig(combatConfig);
        configFactory.setMsgUtils(msgUtils);
        commandHandler.setMsgUtils(msgUtils);
        eventListener.setMsgUtils(msgUtils);
    }

}
